package org.example;

import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * 限流时,将请求者的ip作为限流时使用的key
 */
@Component
public class IpKeyResolver implements KeyResolver {
    @Override
    public Mono<String> resolve(ServerWebExchange exchange) {
        String hostName = exchange.getRequest().getRemoteAddress().getHostName();
        System.out.println("限流标记: "+hostName);
        return Mono.just(hostName);
    }
}